package com.beem.project.beem.providers;

import android.content.ContentResolver;
import android.database.Cursor;
import android.net.Uri;
import android.provider.BaseColumns;

public class Accounts implements BaseColumns{

	private int id;
	private String accountSharedPrefs;
	private int accountOrderby;
	/**
	 * Constructor.
	 */
	public Accounts() {

	}

	public static final Uri CONTENT_URI = Uri.parse("content://" + MessageProvider.AUTHORITY + "/accounts");
	public static final String CONTENT_TYPE = "vnd.android.cursor.dir/vnd.com.beem.project.beem.provider.accounts";
	public static final String CONTENT_ITEM_TYPE = "vnd.android.cursor.item/vnd.com.beem.project.beem.provider.accounts";

	public static final String _ID = "_id";
	public static final String ACCOUNT_SHARED_PREFS = "_shared_prefs";
	public static final String ACCOUNT_ORDERBY = "_accounts_orderby";

	public int getId() {
		return id;
	}
	public void setId(int id) {
		this.id = id;
	}
	public String getAccountSharedPrefs() {
		return accountSharedPrefs;
	}
	public void setAccountSharedPrefs(String accountSharedPrefs) {
		this.accountSharedPrefs = accountSharedPrefs;
	}
	public int getAccountOrderby() {
		return accountOrderby;
	}
	public void setAccountOrderby(int accountOrderby) {
		this.accountOrderby = accountOrderby;
	}
	
	public Accounts lastAccounts(ContentResolver cr){
		Accounts account = null;
		String sortOrder = "_id DESC";
		Uri uri = CONTENT_URI.buildUpon().appendQueryParameter("limit", "limit 1").build();
		Cursor c = cr.query(uri, null, null, null, sortOrder);
		if(c.moveToFirst()){
			account = getAccountsToCursor(c);
		}
		return account;
		
	}
	private Accounts getAccountsToCursor(Cursor c){
		id=c.getInt(c.getColumnIndexOrThrow(_ID));
		accountSharedPrefs=c.getString(c.getColumnIndexOrThrow(ACCOUNT_SHARED_PREFS));
		accountOrderby=c.getInt(c.getColumnIndexOrThrow(ACCOUNT_ORDERBY));
		return this;
	}
}
